package com.caiden_micheal.user.web;

import com.caiden_micheal.base.aop.annotation.PermissionVerify;
import com.caiden_micheal.base.domain.AjxResult;
import com.caiden_micheal.user.service.UserService;
import com.caiden_micheal.user.vo.AddUserPermissionVO;
import com.caiden_micheal.user.vo.RemoveUserPermissionVO;
import com.caiden_micheal.user.vo.UserQueryVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserPermissionController {
    @Autowired
    private UserService userService;

    @PermissionVerify(permissionArray = {"sys:permissionManagement:assignUser"})
    @PostMapping("/userQueryByPermission")
    public AjxResult userQueryByPermission(@RequestBody UserQueryVO userQueryVO) {
        return AjxResult.success(userService.findUsersByConditionPermission(userQueryVO));
    }

    @PermissionVerify(permissionArray = {"sys:permissionManagement:assignUser"})
    @PostMapping("/userQueryExcludePermission")
    public AjxResult userQueryExcludePermission(@RequestBody UserQueryVO userQueryVO) {
        return AjxResult.success(userService.findUsersExcludeConditionPermission(userQueryVO));
    }

    @PermissionVerify(permissionArray = {"sys:permissionManagement:assignUser"})
    @PostMapping("/addUserPermission")
    public AjxResult addUserPermission(@RequestBody AddUserPermissionVO addUserPermissionVO) {
        return userService.addUserPermission(addUserPermissionVO);
    }

    @PermissionVerify(permissionArray = {"sys:permissionManagement:assignUser"})
    @PostMapping("/removeUserPermission")
    public AjxResult removeUserPermission(@RequestBody RemoveUserPermissionVO removeUserPermissionVO) {
        return userService.removeUserPermission(removeUserPermissionVO);
    }

}
